home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / bcfamily / source / beep.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-12  |  1.1 KB  |  50 lines

  1. //
  2. //    *******************************************************************
  3. //      JdeBP C++ Library Routines      General Public Licence v1.00
  4. //          Copyright (c) 1991,1992  Jonathan de Boyne Pollard
  5. //    *******************************************************************
  6. //
  7. // Part of FamAPI.LIB
  8. //
  9.  
  10. #include "famapi.h"
  11. #include "dosdos.h"
  12.  
  13. /* The speaker port (bits 2-7 used elsewhere) */
  14. #define SPEAKER 0x61
  15.  
  16. //
  17. //  enable or disable the speaker, and tones sent to it
  18. //
  19. static void
  20. speaker ( int on, int speak )
  21. {
  22.     int val = inp(SPEAKER);
  23.  
  24.     val = (val & ~3) | (speak ? 2 : 0) | (on ? 1 : 0);
  25.     outp(SPEAKER, val);
  26. }
  27.  
  28. //
  29. //  Make a sound
  30. //
  31. void _APICALL
  32. DosBeep ( unsigned short frequency, unsigned short duration )
  33. {
  34.     unsigned short count = 0 ;
  35.     long remainder = 1193180L ;
  36.  
  37.     //
  38.     // Borland C++ long division would call a helper routine in the library.
  39.     //
  40.     while ((remainder -= (long)frequency) > 0) count ++ ;
  41.  
  42.     outp(0x43, 0xb6);
  43.     outp(0x42, count % 256);
  44.     outp(0x42, count / 256);
  45.  
  46.     speaker(1, 1);
  47.     DosDosSleep(duration) ;
  48.     speaker(1, 0);
  49. }
  50.